package com.daoeping.action;

import java.util.ArrayList;
import java.util.List;

import com.daoeping.data.Bzn_question;
import com.daoeping.data.Bzn_questionfollow;
import com.daoeping.domain.JsonData;
import com.daoeping.domain.Page;
import com.daoeping.domain.TableData;
import com.daoeping.service.Bzn_questionfollowService;
import com.daoeping.util.ConverntJsonData;
import com.opensymphony.xwork2.ActionContext;

public class Bzn_questionfollowAction {
	private JsonData jsonData;
	private Bzn_questionfollow bzn_questionfollow;
    private Bzn_questionfollowService bzn_questionfollowService;
    private Bzn_question bzn_question;
	private Page page;
	private TableData tableData;
	
	public Bzn_question getBzn_question() {
		return bzn_question;
	}

	public void setBzn_question(Bzn_question bzn_question) {
		this.bzn_question = bzn_question;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public TableData getTableData() {
		return tableData;
	}

	public void setTableData(TableData tableData) {
		this.tableData = tableData;
	}

	public JsonData getJsonData() {
		return jsonData;
	}

	public void setJsonData(JsonData jsonData) {
		this.jsonData = jsonData;
	}

	public Bzn_questionfollowService getBzn_questionfollowService() {
		return bzn_questionfollowService;
	}

	public void setBzn_questionfollowService(
			Bzn_questionfollowService bzn_questionfollowService) {
		this.bzn_questionfollowService = bzn_questionfollowService;
	}

	public Bzn_questionfollow getBzn_questionfollow() {
		return bzn_questionfollow;
	}

	public void setBzn_questionfollow(Bzn_questionfollow bzn_questionfollow) {
		this.bzn_questionfollow = bzn_questionfollow;
	}
	public String addBzn_questionfollow(){
		jsonData = new JsonData();
		List<String> list = new ArrayList<String>();
		System.out.println(bzn_questionfollow.getBzn_question().getId());
		if(bzn_questionfollowService.findBzn_questionfollowById(bzn_questionfollow)!=null){
			return "exception";
		}
		if(bzn_questionfollowService.addBzn_questionfollow(bzn_questionfollow)){
			list.add(bzn_questionfollow.getId()+"");
			list.add("follow_add");
			list.add(bzn_questionfollow.getBzn_question().getId()+"");
		}
		ActionContext.getContext().getSession().put("follow", bzn_questionfollow.getId());
		jsonData.setJsonData(new ConverntJsonData().getJsonData(list).toString());
		bzn_questionfollow = null;
		return "addBzn_questionfollow";
		
	}
	
	public String findAllBzn_questionfollowByPage(){
		jsonData = new JsonData();
		jsonData = bzn_questionfollowService.findAllBzn_questionfollowByPage(page, tableData, bzn_question);
		return "findAllBzn_questionfollowByPage";
	}
	
	public String delBzn_questionfollow(){
		jsonData = new JsonData();
		List<String> list = new ArrayList<String>();
		System.out.println(bzn_questionfollow.getId());
		if(bzn_questionfollowService.delBzn_questionfollow(bzn_questionfollow)){
			if(bzn_questionfollow.getBzn_question()!=null){
				list.add(bzn_questionfollow.getBzn_question().getId()+"");
			}else{
				return "exception";
			}
			list.add("follow_del");
			ActionContext.getContext().getSession().put("follow", "");
			jsonData.setJsonData(new ConverntJsonData().getJsonData(list).toString());
			return "delBzn_questionfollow";
		}else{
			return "exception";
		}
		
		
	}
	
}
